package cn.big.bigd;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.big.bigd.ybp.dao.YbpRoleDAO;
import cn.big.bigd.ybp.model.YbpRole;
import cn.big.bigd.ybp.service.YbpUserService;

/**
 * 
 * @author wangfan
 *
 */
@Component
public class DBSeeder {

    public static final Logger LOGGER = LoggerFactory.getLogger(DBSeeder.class.getName());


    @Autowired
    private YbpUserService ybpUserService;

    @Autowired
    private YbpRoleDAO ybpRoleDAO;

    @PostConstruct
    public void seedDatabase() {
      
        
        if (ybpRoleDAO.count() == 0) {
        	ybpRoleDAO.save(YbpRole.ADMIN);
        	ybpRoleDAO.save(YbpRole.USER);
        }

        if (ybpUserService.count() == 0) {
        	ybpUserService.createAdminUser("admin@bigd.com","admin", "123456");
            LOGGER.info("");
        }

    }
}
